<?php


namespace app\controllers;


use app\components\BaseAuthController;
use app\helpers\BinHelper;
use yii\helpers\Url;

class HardwareController extends BaseAuthController {

    public $name = '硬件信息';

    public function actionIndex() {
        $url = Url::to(['data']);
        $this->view->registerJs("window.hardware = '{$url}';", 2);
        return $this->render();
    }

    public function actionData() {
        $output = BinHelper::run('HardInfoGet', NULL);
        $data = [];
        if (is_array($output) && isset($output[0])) {
            $lines = explode(";", $output[0]);
            foreach ($lines as $line) {
                $tmp = explode(':', $line);
                $data[$tmp[0]] = $tmp[1];
            }
        }
        return $this->success($data);
    }
}